/**
 * 
 */
package cn.pfcg.rally.persistent.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import cn.pfcg.rally.domain.bean.QuestionType;
import cn.pfcg.rally.persistent.dao.QuestionTypeDAO;

/**
 * @author cxq
 *
 */
public class QuestionTypeDAOImpl implements QuestionTypeDAO {
	HibernateTemplate hibernateTemplate;
	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.QuestionTypeDAO#deleteQuestionType(java.lang.String)
	 */
	
	public void deleteQuestionType(String name) {
		QuestionType questionType = (QuestionType)hibernateTemplate.find("from QuestionType questionType " + "where questionType.name = ?" , name).get(0);
		hibernateTemplate.delete(questionType);
	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.QuestionTypeDAO#getAllQuestionType()
	 */
	public List<QuestionType> getAllQuestionType() {
		return hibernateTemplate.find("from QuestionType");
	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.QuestionTypeDAO#getQuestionType(java.lang.String)
	 */
	public QuestionType getQuestionType(String name) {
		return (QuestionType)hibernateTemplate.find("from QuestionType questionType " + "where questionType.name = ?" , name).get(0);
	}


	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.QuestionTypeDAO#saveQuestionType(cn.pfcg.rally.domain.bean.QuestionType)
	 */
	public void saveQuestionType(QuestionType questionType) {
		hibernateTemplate.save(questionType);

	}

	/* (non-Javadoc)
	 * @see cn.pfcg.rally.persistent.dao.QuestionTypeDAO#updateQuestionType(java.lang.String)
	 */
	public void updateQuestionType(String name) {
		QuestionType questionType = (QuestionType) hibernateTemplate.find("from QuestionType questionType " + "where questionType.name = ?" , name).get(0);
		hibernateTemplate.update(questionType);
	}

	/**
	 * @param hibernateTemplate the hibernateTemplate to set
	 */
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	

}
